﻿using Microsoft.ClearScript.V8;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Script.ClearScript_V8
{
    /// <summary>
    /// 为V8ScriptEngine添加状态属性
    /// </summary>
    public class Engine : INotifyPropertyChanged
    {
        private RunStatus status;
        /// <summary>
        /// 调试端口
        /// </summary>
        public int Port { get; set; }
        public Engine(V8ScriptEngine scriptEngine, int port)
        {
            Port = port;
            ScriptEngine = scriptEngine;
            Status = RunStatus.None;
        }
        /// <summary>
        /// V8引擎对象
        /// </summary>
        public V8ScriptEngine ScriptEngine { get; private set; }
        /// <summary>
        /// 脚本引擎状态
        /// </summary>
        public RunStatus Status
        {
            get => status;
            set
            {
                status = value;
                NotifyPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        // This method is called by the Set accessor of each property.
        // The CallerMemberName attribute that is applied to the optional propertyName
        // parameter causes the property name of the caller to be substituted as an argument.
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public enum RunStatus
    {
        None,
        Running,
        Error,
        Finished
    }
}
